//
//  TSFindActivityCellViewModel.m
//  TaShuo
//
//  Created by N-X on 2018/3/19.
//  Copyright © 2018年 MRNAN. All rights reserved.
//

#import "TSFindActivityCellViewModel.h"
#import "TSFindActivityCollectionCell.h"
#import "TSFindAcrivityItemViewModel.h"

@interface TSFindActivityCellViewModel()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation TSFindActivityCellViewModel
- (void)bindView:(UIView *)view
{
    UICollectionView * collectionView = (UICollectionView *)view;
    collectionView.delegate = self;
    collectionView.dataSource = self;
    
    [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([TSFindActivityCollectionCell class]) bundle:nil] forCellWithReuseIdentifier:kFindActivityCollectionCellID];
}


#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.activityItems.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TSFindActivityCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kFindActivityCollectionCellID forIndexPath:indexPath];
    TSFindAcrivityItemViewModel * itemVM = self.activityItems[indexPath.item];
    [itemVM bindView:cell];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewFlowLayout * layout = (UICollectionViewFlowLayout *)collectionViewLayout;
    CGFloat itemW = (collectionView.nx_width - collectionView.contentInset.left * 2 - layout.minimumInteritemSpacing) / 2;
    CGFloat itemH = (collectionView.nx_height - collectionView.contentInset.bottom - layout.minimumInteritemSpacing) /2;
    return CGSizeMake(itemW, itemH);
}
@end
